package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.admin.biz.AdminExamDataBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-考试-监控数据
 *
 * @author wcs
 * @since 2024-07-10
 */
@Tag(name = "Admin-考试-监控数据")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/exam/data")
public class AdminExamDataController {

    @NotNull
    private final AdminExamDataBiz biz;

    @Operation(summary = "考试-监控数据-统计分析")
    @OptLog(value = "考试-监控数据-统计分析")
    @GetMapping(value = "/statistics")
    public Result<AdminExamDataStatisticsResp> statistics(@ModelAttribute @Valid AdminExamDataStatisticsReq req) {
        return biz.statistics(req);
    }

    @Operation(summary = "考试-监控数据-用户-分页")
    @OptLog(value = "考试-监控数据-用户-分页")
    @GetMapping(value = "/user/page")
    public Result<Page<AdminExamDataUserPageResp>> userPage(@ModelAttribute @Valid AdminExamDataUserPageReq req) {
        return biz.userPage(req);
    }

    @Operation(summary = "考试-监控数据-记录-分页")
    @OptLog(value = "考试-监控数据-记录-分页")
    @GetMapping(value = "/record/page")
    public Result<Page<AdminExamDataRecordPageResp>> recordPage(@ModelAttribute @Valid AdminExamDataRecordPageReq req) {
        return biz.recordPage(req);
    }

    @Operation(summary = "考试-监控数据-题目分析-分页")
    @OptLog(value = "考试-监控数据-题目分析-分页")
    @GetMapping(value = "/question/analysis/page")
    public Result<Page<AdminExamDataQuestionAnalysisPageResp>> questionAnalysisPage(@ModelAttribute @Valid AdminExamDataQuestionAnalysisPageReq req) {
        return biz.questionAnalysisPage(req);
    }

    @Operation(summary = "考试-监控数据-题目分析-详情-分页")
    @OptLog(value = "考试-监控数据-题目分析-详情-分页")
    @GetMapping(value = "/question/analysis/detail/page")
    public Result<Page<AdminExamDataQuestionAnalysisDetailPageResp>> questionAnalysisDetailPage(@ModelAttribute @Valid AdminExamDataQuestionAnalysisDetailPageReq req) {
        return biz.questionAnalysisDetailPage(req);
    }

    @Operation(summary = "考试-监控数据-排行榜-分页")
    @OptLog(value = "考试-监控数据-排行榜-分页")
    @GetMapping(value = "/rank/page")
    public Result<Page<AdminExamDataRankPageResp>> rankPage(@ModelAttribute @Valid AdminExamDataRankPageReq req) {
        return biz.rankPage(req);
    }

    @Operation(summary = "考试-监控数据-阅卷-列表", description = "在阅卷页面列出所有需要评阅的考试记录，进行快速切换进行评阅")
    @OptLog(value = "考试-监控数据-阅卷-列表")
    @GetMapping(value = "/evaluation/list")
    public Result<List<AdminExamDataEvaluationListResp>> evaluationList(@ModelAttribute @Valid AdminExamDataEvaluationListReq req) {
        return biz.evaluationList(req);
    }

    @Operation(summary = "考试-监控数据-阅卷-开始评阅")
    @OptLog(value = "考试-监控数据-阅卷-开始评阅")
    @Parameter(name = "recordId", description = "考试记录ID", required = true)
    @GetMapping(value = "/evaluation/start")
    public Result<AdminExamDataEvaluationStartResp> evaluationStart(@RequestParam Long recordId) {
        return biz.evaluationStart(recordId);
    }

    @Operation(summary = "考试-监控数据-阅卷-结束评阅")
    @OptLog(value = "考试-监控数据-阅卷-结束评阅")
    @PutMapping(value = "/evaluation/end")
    public Result<String> evaluationEnd(@RequestBody @Validated AdminExamDataEvaluationEndReq req) {
        return biz.evaluationEnd(req);
    }

    @Operation(summary = "考试-监控数据-阅卷-状态-更新")
    @OptLog(value = "考试-监控数据-阅卷-状态-更新")
    @PutMapping(value = "/evaluation/update/status")
    public Result<String> evaluationUpdateStatus(@RequestBody @Valid AdminExamDataEvaluationUpdateStatusReq req) {
        return biz.evaluationUpdateStatus(req);
    }

    @Operation(summary = "考试-监控数据-阅卷-答案-编辑")
    @OptLog(value = "考试-监控数据-阅卷-答案-编辑")
    @PutMapping(value = "/evaluation/update/answer")
    public Result<String> userAnswerEdit(@RequestBody @Valid AdminExamDataUserAnswerEditReq req) {
        return biz.userAnswerEdit(req);
    }

    @Operation(summary = "考试-个人-分页）")
    @OptLog(value = "考试-个人-分页）")
    @GetMapping(value = "/personal/page")
    public Result<Page<AdminExamDataPersonalPageResp>> personalPage(@ModelAttribute @Valid AdminExamDataPersonalPageReq req) {
        return biz.personalPage(req);
    }
}
